<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@include file="/WEB-INF/jsp/common/taglibs.jspf"%>
<es:contentHeader />
<%@include file="/WEB-INF/jsp/common/import-upload-css.jspf"%>
<div class="panel">

	<ul class="nav nav-tabs">
		<shiro:hasPermission name="vip:advertising:create">
			<c:if test="${op eq '新增'}">
				<li ${op eq '新增' ? 'class="active"' : ''}><a
					href="${ctx}/vip/advertising/create?BackURL=<es:BackURL/>"> <i
						class="icon-file-alt"></i> 新增
				</a></li>
			</c:if>
		</shiro:hasPermission>

		<c:if test="${not empty m.id}">
			<li ${op eq '查看' ? 'class="active"' : ''}><a
				href="${ctx}/vip/advertising/${m.id}?BackURL=<es:BackURL/>"> <i
					class="icon-eye-open"></i> 查看
			</a></li>
			<shiro:hasPermission name="vip:advertising:update">
				<li ${op eq '修改' ? 'class="active"' : ''}><a
					href="${ctx}/vip/advertising/${m.id}/update?BackURL=<es:BackURL/>">
						<i class="icon-edit"></i> 修改
				</a></li>
			</shiro:hasPermission>

			<shiro:hasPermission name="vip:advertising:delete">
				<li ${op eq '删除' ? 'class="active"' : ''}><a
					href="${ctx}/vip/advertising/${m.id}/delete?BackURL=<es:BackURL/>">
						<i class="icon-trash"></i> 删除
				</a></li>
			</shiro:hasPermission>
		</c:if>
		<li><a href="<es:BackURL/>" class="btn btn-link"> <i
				class="icon-reply"></i> 返回
		</a></li>
	</ul>

	<form:form id="editForm" method="post" commandName="m"
		cssClass="form-horizontal" enctype="multipart/form-data">
		<!--上一个地址 如果提交方式是get 需要加上-->
		<%--<es:BackURL hiddenInput="true"/>--%>

		<es:showGlobalError commandName="m" />

		<form:hidden path="id" />

		<div class="control-group">
			<form:label path="advName" cssClass="control-label">广告名称：</form:label>
			<div class="controls">
				<form:input path="advName" cssClass="input-xxlarge validate[required]"
					placeholder="5到10个字母、数字、下划线" />
			</div>
		</div>

		<div class="control-group">
			<form:label path="type" cssClass="control-label">显示位置：</form:label>
			<div class="controls">
				<form:select path="type" cssClass="validate[required]">
					<form:option value="1">首页一</form:option>
					<form:option value="2">首页二</form:option>
					<form:option value="3">首页三</form:option>
					<form:option value="4">首页四</form:option>
					<form:option value="5">首页五</form:option>
					<form:option value="6">微贴一</form:option>
					<form:option value="7">微贴二</form:option>
					<form:option value="8">微贴三</form:option>
					<form:option value="9">微贴四</form:option>
					<form:option value="10">微贴五</form:option>
				</form:select>
			</div>
		</div>
		<%--logo --%>
		<div class="control-group" style="margin-bottom: 0px;<c:if test="${empty m.advLogo}">display: none</c:if>">
                <label for="files" class="control-label"></label>
                <div class="controls">
                    <div class="ajax-upload-view"></div>
                    <form:hidden path="advLogo"/>
                </div>
        </div>
        <%-- --%>
        <c:if test="${not empty m.advLogo}">
            <div class="control-group">
                <form:label path="advLogo" cssClass="control-label">首页显示图片</form:label>
                <div class="controls">
                    <es:showAttachment filename="${m.advLogo}" showImage="true" width="auto" height="160"/>
                    <form:hidden path="advLogo"/>
                </div>
            </div>
        </c:if>
        <c:if test="${op ne '查看'}">
		<div class="control-group">
			<label for="files" class="control-label">LOGO</label>
			<div class="controls">
				<label for="files" class="btn btn-success fileinput-button">
					<i class="icon-plus icon-white"></i> <span>添加文件...</span> <input
					type="file" id="files" name="files[]" data-url="${ctx}/ajaxUpload"
					multiple>
				</label>
			</div>
		</div>
		</c:if>
		
		<div class="control-group">
			<form:label path="advContent" cssClass="control-label">广告内容</form:label>
			<div class="controls">
				<c:choose>
					<c:when test="${op ne '查看'}">
						<form:textarea path="advContent" cssClass="validate[required]"
							cssStyle="width: 550px;height: 200px;" />
					</c:when>
					<c:otherwise>
                        ${m.advContent}
                    </c:otherwise>
				</c:choose>
			</div>
		</div>

		<div class="control-group">
			<form:label path="advDisTip" cssClass="control-label">特别提示：</form:label>
			<div class="controls">
				<form:input path="advDisTip" placeholder="5到10个字母、数字、下划线" />
			</div>
		</div>
		<div class="control-group">
			<form:label path="remark" cssClass="control-label">备注信息：</form:label>
			<div class="controls">
				<form:input path="remark" placeholder="备注信息 " />
			</div>
		</div>

		<div class="control-group">
			<form:label path="show" cssClass="control-label">是否显示</form:label>
			<div class="controls inline-radio">
				<form:radiobuttons path="show" items="${booleanList}"
					itemLabel="info" itemValue="value" cssClass="validate[required]" />
			</div>
		</div>

		<c:if test="${op eq '新增'}">
			<c:set var="icon" value="icon-file-alt" />
		</c:if>
		<c:if test="${op eq '修改'}">
			<c:set var="icon" value="icon-edit" />
		</c:if>
		<c:if test="${op eq '删除'}">
			<c:set var="icon" value="icon-trash" />
		</c:if>

		<div class="control-group">
			<div class="controls">
				<button type="submit" class="btn btn-primary">
					<i class="${icon}"></i> ${op}
				</button>
				<a href="<es:BackURL/>" class="btn"> <i class="icon-reply"></i>
					返回
				</a>
			</div>
		</div>


	</form:form>
</div>
<es:contentFooter />
<%@include file="/WEB-INF/jsp/common/import-upload-simple-js.jspf"%>
<%@include file="/WEB-INF/jsp/common/import-editor-js.jspf"%>

<script type="text/javascript">
	$(function() {
		$('.fileinput-button input[type="file"]').fileupload({
			dataType : "json"
		});
		$('.fileinput-button input[type="file"]')
				.fileupload(
						"option",
						{
							progressall : function(e, data) {
								var view = $(".ajax-upload-view");
								view.parent().parent().show();
								var progressBar = view.find(".progress");
								if (progressBar.size() == 0) {
									var progressBarTemplate = '<div class="progress progress-striped">'
											+ '<div class="bar"></div>' + '</div>';
									progressBar = view.append(progressBarTemplate);
								}
								var progress = parseInt(data.loaded / data.total * 100, 10);
								progressBar.find(".bar").css("width", progress + "%");
							},
							start : function(e) {
								$(".ajax-upload-view").html("");
								var submitBtn = $(this).closest("form").find(":submit");
								submitBtn.data("value", submitBtn.val()).val("上传文件中...").prop("disabled", true);
							},
							//上传完成
							done : function(e, data) {
								$
										.each(
												data.result.files,
												function(index, file) {
													if (file.error) {
														$(".ajax-upload-view").html(
																"<div class='alert alert-error'>" + file.error
																		+ "</div>");
													} else {
														$("[name='advLogo']").val(file.url);
														var msg = "<div class='alert alert-success'><strong>上传成功！</strong><br/>{preview}</div>";
														var preview = "";
														var url = ctx + "/" + file.url;
														var thumbnail_url = ctx + "/" + file.thumbnail_url;
														if ($.app.isImage(file.name)) {
															preview = "<a href='{url}' target='_blank'><img src='{thumbnail_url}' title='{name}' height='120px'/></a>"
														} else {
															preview = "<a href='{url}' target='_blank'>{name}</a>"
														}
														preview = preview.replace("{url}", url).replace(
																"{thumbnail_url}", thumbnail_url).replace("{name}",
																file.name);
														msg = msg.replace("{preview}", preview);
														$(".ajax-upload-view").html(msg);

													}
												});
								var submitBtn = $(this).closest("form").find(":submit");
								submitBtn.val(submitBtn.data("value")).prop("disabled", false);
							}
						});
		<c:choose>
		<c:when test="${op eq '删除'}">
		//删除时不验证 并把表单readonly
		$.app.readonlyForm($("#editForm"), false);
		</c:when>
		<c:when test="${op eq '查看'}">
		$.app.readonlyForm($("#editForm"), true);
		</c:when>
		<c:otherwise>
		//自定义ajax验证  ajax[ajaxNameCall] 放到验证规则的最后（放到中间只有当submit时才验证）
		$.validationEngineLanguage.allRules.ajaxNameCall = {
			"url" : "${ctx}/vip/advertising/validate",
			//动态提取的数据。验证时一起发送
			extraDataDynamic : [ '#id' ],
			//验证失败时的消息
			//"alertText": "* 该名称已被其他人使用",
			//验证成功时的消息
			//"alertTextOk": "该名称可以使用",
			"alertTextLoad" : "* 正在验证，请稍等。。。"
		};
		$.validationEngineLanguage.allRules.username = {
			"regex" : /^\w{5,10}$/,
			"alertText" : "* 5到10个字母、数字、下划线"
		};
		var validationEngine = $("#editForm").validationEngine();
		<es:showFieldError commandName="m"/>
		</c:otherwise>
		</c:choose>
		//editor
		var editor = KindEditor.create('textarea[name="advContent"]', {
			themeType : 'simple',
			uploadJson : '${ctx}/kindeditor/upload',
			fileManagerJson : '${ctx}/kindeditor/filemanager',
			allowFileManager : true,
			afterBlur : function() {
				this.sync();
			}
		});
	});
</script>